package com.task.core.mapper;

import java.util.List;

import com.task.core.domain.info.DataContentInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import com.task.core.domain.DataImportHeadInfo;
import com.task.core.domain.DataOperationInfo;
import com.task.core.domain.ExportFileInfo;
import com.task.core.domain.info.DataHistoryImportInfo;
import com.task.core.domain.info.MissionSuccessRedisMap;
import com.task.core.dto.request.DataFileUploadRequestDTO;
import com.task.core.dto.request.DataOperationRequestDTO;
import com.task.core.dto.request.ExportFileRequestDTO;
import com.task.core.task.into.DataIncrementCodeGroupInfo;

/**
 * @author 迪迦.
 * @date 2024/11/11 13:51
 */
@Mapper
public interface DataOperationMapper {

  List<DataOperationInfo> getNotUseData(
      @Param("limit") int limit,
      @Param("dataSourceCodeList") List<String> dataSourceCodeList);

  DataOperationInfo getDataById(@Param("dataId") String dataId, @Param("tableName") String tableName,
      @Param("tNum") Integer tNum);

  void insertImportData(@Param("tableName") String tableName,
      @Param("value") List<DataOperationInfo> value);

  void insertImportHistory(@Param("request") DataFileUploadRequestDTO request,
      @Param("code") String code,
      @Param("uploadStatus") String uploadStatus);

  void updateImportHistory(@Param("code") String code, @Param("uploadStatus") String uploadStatus);

  Integer deleteDataByFileCode(@Param("fileCode") String fileCode,
      @Param("tableName") String tableName);

  void copyTaskData(String tableName);

  List<DataOperationInfo> getDataByPage(@Param("request") DataOperationRequestDTO request,
      @Param("startIndex") int startIndex, @Param("pageSize") int pageSize);
  //
  //List<DataOperationInfo> getDataByPageDescAfterToBefore(@Param("request") DataOperationRequestDTO request,
  //    @Param("startIndex") int startIndex, @Param("pageSize") int pageSize);
  //
  //List<DataOperationInfo> getDataByPageDescBeforeToAfter(@Param("request") DataOperationRequestDTO request,
  //    @Param("startIndex") int startIndex, @Param("pageSize") int pageSize);

  List<DataOperationInfo> getDataByPageOld(DataOperationRequestDTO request);

  List<Integer> getAllDataCount(@Param("request") DataOperationRequestDTO request);

  List<String> getDataForExport(@Param("pageNum") int pageNum,
      @Param("exportPageSize") int exportPageSize,
      @Param("tableName") String tableName,
      @Param("request") DataOperationRequestDTO request);

  void insertImportDataHead(@Param("headString") String headString,
      @Param("fileCode") String fileCode,
      @Param("dataSourceCode") String dataSourceCode,
      @Param("operationBy") Long operationBy,
      @Param("fileName") String fileName);

  String getDataHeader(String fileCode);

  void insertExportFileHistory(@Param("exportFileCode") String exportFileCode,
      @Param("userId") Long userId,
      @Param("sourceCode") String sourceCode,
      @Param("fileName") String fileName);

  List<ExportFileInfo> getExportFiles(ExportFileRequestDTO request);

  void updateDownloadStatus(@Param("code") String code, @Param("status") boolean status);

  void updateExportFileHistory(@Param("code") String exportFileCode, @Param("size") Long size);

  List<DataHistoryImportInfo> getImportHistory(DataOperationRequestDTO request);

  List<DataOperationInfo> getRefererDataByPage(@Param("request") DataOperationRequestDTO request,
      @Param("startIndex") int startIndex, @Param("pageSize") int pageSize);

  List<Integer> getAllRefererDataCount(@Param("request") DataOperationRequestDTO request);

  List<DataOperationInfo> getNotUseRefererData(
      @Param("limit") int limit,
      @Param("dataSourceCodeList") List<String> dataSourceCodeList);

  int dataUseFailedIncrement(@Param("missionCode") String missionCode,
      @Param("dataCode") String dataCode);

  void dataUseFailedInsert(@Param("missionCode") String missionCode,
      @Param("dataCode") String dataCode,
      @Param("tNum") String tNum,
      @Param("dataType") String dataType);

  void insertHistoryDataGetIndex(
      @Param("columnAdd") String columnAdd,
      @Param("columnAddValue") String columnAddValue,
      @Param("dataCode") String dataCode,
      @Param("indexTableCode") String indexTableCode,
      @Param("tableName") String tableName,
      @Param("sourceCode") String sourceCode
  );

  void deleteHistoryDataGetIndex(@Param("code") String indexTableCode,
      @Param("tableName") String tableName);

  void insertHistoryDataGetDetail(
      @Param("tableName") String tableName,
      @Param("id") String id,
      @Param("code") String code,
      @Param("missionCode") String missionCode,
      @Param("missionDetail") byte[] missionDetail,
      @Param("deviceCode") String deviceCode,
      @Param("deviceDetail") byte[] deviceDetail,
      @Param("dataCode") String dataCode,
      @Param("dataDetail") byte[] dataDetail,
      @Param("tNum") Integer tNum,
      @Param("dataType") String dataType,
      @Param("dataId") String dataId,
      @Param("sendCode") String sendCode,
      @Param("missionSessionCode") String missionSessionCode
      );

  void updateHistoryDataGetDetail(@Param("tableName") String tableName,
      @Param("status") boolean status, @Param("code") String code);

  void insertMissionGetHistory(
      @Param("tableName") String tableName,
      @Param("id") String id,
      @Param("code") String code,
      @Param("advertiserCode") String advertiserCode,
      @Param("affiliateCode") String affiliateCode,
      @Param("groupCode") String groupCode,
      @Param("missionCode") String missionCode,
      @Param("missionDetail") byte[] missionDetail,
      @Param("planCode") String planCode,
      @Param("planDetail") byte[] planDetail,
      @Param("deviceCode") String deviceCode,
      @Param("deviceDetail") byte[] deviceDetail);

  void updateHistoryMissionGetDetail(@Param("tableName") String tableName,
      @Param("missionSendCode") String missionSendCode,
      @Param("status") Boolean status);

  void updateHistoryMissionSuccessGetDetails(@Param("tableName") String tableName, @Param("list") List<MissionSuccessRedisMap> list);

  void incrementUseCount(@Param("code") String code, @Param("tableName") String tableName);

  void decrementUseCount(@Param("code") String code, @Param("tableName") String tableName);

  List<DataImportHeadInfo> getImportFileHeader(@Param("sourceCode") String sourceCode);

  void updateHistoryMissionFailedGetDetails(@Param("tableName") String tableName, @Param("list") List<MissionSuccessRedisMap> list);

  void incrementUseCountBatch(@Param("tableName") String tableName, @Param("dataList") List<DataIncrementCodeGroupInfo> dataIncrementCodeGroupInfos);


  Integer getUseDataCountByFilterAndSourceCode(@Param("missionCode") String missionCode,
                                               @Param("affiliateCode") String affiliateCode,
                                               @Param("advertiserCode") String advertiserCode,
                                               @Param("sourceCode") String sourceCode,
                                               @Param("indexTableNames") List<String> indexTableNames,
                                               @Param("failureThreshold")String failureThreshold);

  DataOperationInfo getByID(String s);

  void deleteDataBySourceCode(@Param("sourceCode")String sourceCode, @Param("tableName") String tableName);

  void deleteRefereBySourceCode(@Param("tableName")String tableName, @Param("sourceCode")String sourceCode);

    DataContentInfo showDatasource(@Param("datasourceCode")String datasourceCode,@Param("tableName") List<String> tableName);

  boolean tableIsExits(String tableName);
}
